package com.atguigu.eduorder.service.impl;

import com.atguigu.commonutils.orderVo.CourseWebOrderVo;
import com.atguigu.commonutils.orderVo.UcenterMemberOrderVo;
import com.atguigu.eduorder.entity.Order;
import com.atguigu.eduorder.feign.EduCilent;
import com.atguigu.eduorder.feign.UcenterClient;
import com.atguigu.eduorder.mapper.OrderMapper;
import com.atguigu.eduorder.service.OrderService;
import com.atguigu.eduorder.utils.OrderNoUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-06-24
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Autowired
    EduCilent eduCilent;
    @Autowired
    UcenterClient ucenterClient;

    /**
     * 生成订单
     * @param courseId
     * @param memberId
     * @return
     */
    @Override
    public String generateOrder(String courseId, String memberId) {
        //远程调用ucenter服务获取会员信息
        UcenterMemberOrderVo memberInfo = ucenterClient.getMemberInfoOrder(memberId);
        //远程调用edu服务获取课程信息
        CourseWebOrderVo courseInfo = eduCilent.getCourseFrontInfoOrder(courseId);
        Order order=new Order();
        //订单号，工具类生成
        order.setOrderNo(OrderNoUtil.getOrderNo());
        //课程id
        order.setCourseId(courseId);
        order.setCourseTitle(courseInfo.getTitle());
        order.setCourseCover(courseInfo.getCover());
        order.setTeacherName("test");
        order.setTotalFee(courseInfo.getPrice());
        order.setMemberId(memberId);
        order.setMobile(memberInfo.getMobile());
        order.setNickname(memberInfo.getNickname());
        //支付状态，刚生成的订单默认是未支付
        order.setStatus(0);
        //支付类型，默认是微信支付
        order.setPayType(1);
        baseMapper.insert(order);
        //返回订单号
        return order.getOrderNo();
    }
}
